package com.concurrency.example.singleton;

import com.concurrency.annoations.Recommend;
import com.concurrency.annoations.ThreadSafe;

@ThreadSafe
@Recommend
public class SingletonExample3 {
    private SingletonExample3(){};

    public static SingletonExample3 getInstance(){
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton{
        INSTANCE;

        private  SingletonExample3 singleton = null;

        //JVM保证这个方法只调用一次
        Singleton(){
            singleton = new SingletonExample3();
        }
        private  SingletonExample3 getInstance(){
            return singleton;
        }
    }
}
